package org.nox.helloseries.core.connector.tracker.impl;

import org.apache.commons.lang.StringUtils;
import org.jdom2.Element;
import org.nox.helloseries.core.connector.tracker.AbstractRSSTorrentSearch;
import org.nox.helloseries.domain.NomTracker;
import org.nox.helloseries.domain.Serie;

public class Torrent411TorrentSearch extends AbstractRSSTorrentSearch
{
	private final String baseURL = "http://www.t411.me/torrents/rss/?search=";

	@Override
	protected double getTailleFichier( Element e )
	{
		return Double.parseDouble( e.getChild( "enclosure" ).getAttributeValue( "length" ) ) / 1000000;
	}

	@Override
	protected int getSeeds( Element e )
	{
		String description = e.getChildText( "description" );
		try{
			return Integer.parseInt( StringUtils.substringBetween( description, "Status: ", " seeders" ) );
		}
		catch (NumberFormatException ex)
		{
			return 0;
		}
	}

	@Override
	protected String getTitre( Element e )
	{
		return e.getChildText( "title" );
	}

	@Override
	protected String getUrl( Element e )
	{
		String url = e.getChild( "enclosure" ).getAttributeValue( "url" ).replace( "&amp;", "&" );
		return url;
	}

	@Override
	protected String getUrlRecherche( Serie serie )
	{
		return baseURL + serie.toString().replaceAll( " ", "+" );
	}

	@Override
	protected NomTracker getNomTracker()
	{
		return NomTracker.TORRENT411;
	}

}
